package com.lmz.product.web;

import com.lmz.product.VO.catalog2Vo;
import com.lmz.product.entity.CategoryEntity;
import com.lmz.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class indexController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping({"/", "/index.html"})
    public String indexPage(Model model) {
        //查询出所有的一级分类
        List<CategoryEntity> catalogEntryList = categoryService.getLevelOneCategory();
        model.addAttribute("categorys", catalogEntryList);
        return "index";
    }


    //index/catalog.json
    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String, List<catalog2Vo>> getCatalogJson() {
        Map<String, List<catalog2Vo>> res = categoryService.getCatalgJson();
        return res;
    }
}